//
//  ChatViewController.m
//  EaseIMTest
//
//  Created by yshow on 16/8/25.
//  Copyright © 2016年 yshow. All rights reserved.
//

#import "ChatViewController.h"
#import "UserCacheManager.h"

@interface ChatViewController ()<
EaseMessageViewControllerDelegate,
EaseMessageViewControllerDataSource>


@property (nonatomic,copy) NSString *userImgUrl;
@property (nonatomic,copy) NSString *userName;
@property (nonatomic,strong) NSMutableArray *messageArray;

@end

@implementation ChatViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.messageArray = [NSMutableArray array];
    self.delegate = self;
    self.dataSource = self;
    self.showRefreshHeader = YES;
}

-(id<IMessageModel>)messageViewController:(EaseMessageViewController *)viewController modelForMessage:(EMMessage *)message
{
    id <IMessageModel>model = nil;
    model = [[EaseMessageModel alloc]initWithMessage:message];
    BOOL isSender = model.isSender;
    
   
    if (isSender) {
        model.nickname = @"张晓亮";
        model.avatarImage = [UIImage imageNamed:@"EaseUIResource.bundle/user"];
    }else{
        [UserCacheManager getUserInfoForKey:message.conversationId block:^(NSString *userName, NSString *userImgUrl) {
            model.avatarURLPath = userImgUrl;
            model.nickname = userName;
        }];
    }
    
    return model;
    
}

-(void)messageViewController:(EaseMessageViewController *)viewController didSendMessageModel:(id<IMessageModel>)messageModel
{
    EMMessage *message = messageModel.message;
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:message.ext];
    [dict setObject:@"张小亮" forKey:@"username"];
    [dict setObject:@"http://101.201.72.144/upload/avatar/ca97959c5342085ceb284d438c531289.png" forKey:@"userimageurl"];
    message.ext = dict;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
